package work.cdc.pagesetup;

import cn.hutool.core.io.FileUtil;
import cn.hutool.http.HttpUtil;
import lombok.extern.slf4j.Slf4j;

import java.nio.charset.Charset;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

@Slf4j
public class OssFileValidateDemo {
    private final static String basePath = "C:\\work-records\\fred\\l-cdc杂志迁移到生产\\2023-12-06";
//    private final static String prefix = "https://oss-socialcrm-show-uat.oss-cn-shanghai.aliyuncs.com";
    private final static String prefix = "https://oss-socialcrm-show-uat.oss-accelerate.aliyuncs.com";
    private final static String fileName = "\\goods.js";
//    private final static String fileName = "\\pagesetup.js";

//TODO 支持多个文件、文件数量校验放在底部
    public static void main(String[] args) {
        List<String> strings = FileUtil.readLines(basePath + fileName, Charset.defaultCharset());
        Set<String> result = new HashSet<>();
        for (String line : strings) {
            if (line.contains(prefix)) {
                String resource = line.split("\"")[1];
                result.add(resource);
            }
        }
        log.info("【文件解析】资源数量->{}", result.size());
        int count = 0;
        for (String url : result) {
            log.info("【文件下载】count->{},url->{}", ++count, url);
            String filePath = url.split(prefix)[1];
            HttpUtil.downloadFile(url, basePath + filePath);
        }
    }
}
